import React, { useEffect, useState } from "react";

export default function EffectHookCancelDemo() {
  const [count, setcount] = useState(0);

  useEffect(() => {
    //   在这里做一个订阅
    console.log("订阅一些事件");
    return () => {
      // 组件卸载的时候,执行的回调函数
      console.log("取消订阅");
    };
  }, []);
  return (
    <div>
      <h2>EffectHookCancelDemo--{count}</h2>
      <button
        onClick={(e) => {
          setcount(count + 1);
        }}
      >
        +1
      </button>
    </div>
  );
}
